package com.cardbaobao.cardbabyclient.widget;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.cardbaobao.cardbabyclient.R;

import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrUIHandler;
import in.srain.cube.views.ptr.indicator.PtrIndicator;


/**
 * Description:
 * Date: 2017/06/26
 * Created by FHW
 */
public class RotateHeaderHandler extends FrameLayout implements PtrUIHandler {
    private AnimationDrawable animationDrawable;

    public RotateHeaderHandler(Context context) {
        super(context);
        init(context);
    }

    public RotateHeaderHandler(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public RotateHeaderHandler(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.wigdet_head_for_pull, null);
        ImageView imageview = (ImageView) view.findViewById(R.id.iv_loading);
        animationDrawable = (AnimationDrawable) imageview.getBackground();
        addView(view);
    }


    @Override
    public void onUIReset(PtrFrameLayout frame) {
        animationDrawable.stop();
    }

    @Override
    public void onUIRefreshPrepare(PtrFrameLayout frame) {

    }

    @Override
    public void onUIRefreshBegin(PtrFrameLayout frame) {
        animationDrawable.start();
    }

    @Override
    public void onUIRefreshComplete(PtrFrameLayout frame) {

    }

    public void onUIRefreshComplete(PtrFrameLayout frame, boolean isHeader) {

    }

    @Override
    public void onUIPositionChange(PtrFrameLayout frame, boolean isUnderTouch, byte status, PtrIndicator ptrIndicator) {

    }
}
